import pyaudio
import wave

# 打开WAV文件
file_path = "湾妹音频.wav"
wf = wave.open(file_path, "rb")
print(wf.getsampwidth())
print(wf.getnchannels())
print(wf.getframerate())
# 初始化PyAudio
p = pyaudio.PyAudio()

# 打开音频流
stream = p.open(
    format=p.get_format_from_width(wf.getsampwidth()),
    channels=wf.getnchannels(),
    rate=wf.getframerate(),  # 自动获取采样率（应为44100）
    output=True
)

# 分块读取并播放
chunk = 1024
data = wf.readframes(chunk)

while data:
    stream.write(data)
    data = wf.readframes(chunk)

# 清理资源
stream.stop_stream()
stream.close()
p.terminate()